"""modelarts sdk的常量。"""
"""Constants of modelarts sdk."""
# 导入os模块，用于与操作系统交互
# Import the os module for interacting with the operating system
import os
# 导入sys模块，用于与Python解释器交互
# Import the sys module for interacting with the Python interpreter
import sys
# 导入stat模块，用于解释stat()的结果
# Import the stat module for interpreting the results of stat()
import stat

# AKSK认证
# AKSK authentication
AKSK_AUTH = 'aksk'
# ROMA认证
# ROMA authentication
ROMA_AUTH = 'roma'
# HTTPS GET方法
# HTTPS GET method
HTTPS_GET = 'GET'
# HTTPS POST方法
# HTTPS POST method
HTTPS_POST = 'POST'
# HTTPS DELETE方法
# HTTPS DELETE method
HTTPS_DELETE = 'DELETE'
# HTTPS PUT方法
# HTTPS PUT method
HTTPS_PUT = 'PUT'
# ISO时间格式
# ISO time format
ISO_TIME_FORMAT = '%m%d-%H%M%S'
# JSON类型
# JSON type
JSON_TYPE = 'json'

# ROMA主机
# ROMA host
ROMA_HOST = 'http://roma.huawei.com/csb/rest/modelarts'
# ROMA OBS主机
# ROMA OBS host
ROMA_OBS_HOST = "http://roma.huawei.com/csb/api/"
# ROMA OBS存储桶主机
# ROMA OBS bucket host
ROMA_OBS_BUCKET_HOST = 'http://roma.huawei.com/csb/rest/'
# ROMA项目ID
# ROMA project ID
ROMA_PROJECT_ID = 'roma_project_id'
# ROMA内容类型
# ROMA content type
ROMA_CONTENT_TYPE = 'application/json;charset=utf8'

# ModelArts配置文件路径
# ModelArts config file path
MODELARTS_CONFIG_PATH = '~/.modelarts/config.json'

# 支持的区域
# Supported regions
SUPPORTED_REGION = ['cn-north-1', 'cn-north-2', 'cn-north-4', 'cn-north-5',
                    'cn-north-7', 'cn-northeast-1',
                    'cn-east-2', 'cn-south-1', 'ap-southeast-1', 'cn-east-3',
                    'ap-southeast-3', 'cn-hangzhou-1', 'eu-west-0', 'cn-central-221', 'cn-southwest-259']

# 作业状态
# Job states
JOB_STATE = ['JOBSTAT_UNKNOWN', 'JOBSTAT_INIT', 'JOBSTAT_IMAGE_CREATING',
             'JOBSTAT_IMAGE_FAILED',
             'JOBSTAT_SUBMIT_TRYING',
             'JOBSTAT_SUBMIT_FAILED', 'JOBSTAT_DELETE_FAILED',
             'JOBSTAT_WAITING', 'JOBSTAT_RUNNING',
             'JOBSTAT_KILLING',
             'JOBSTAT_COMPLETED', 'JOBSTAT_FAILED', 'JOBSTAT_KILLED',
             'JOBSTAT_CANCELED', 'JOBSTAT_LOST',
             'JOBSTAT_SCALING', 'JOBSTAT_SUBMIT_MODEL_FAILED', 'JOBSTAT_DEPLOY_SERVICE_FAILED',
             'JOBSTAT_CHECK_INIT', 'JOBSTAT_CHECK_RUNNING', 'JOBSTAT_CHECK_RUNNING_COMPLETED',
             'JOBSTAT_CHECK_FAILED']

# ROMA作业等待状态码
# ROMA job waiting status code
ROMA_JOB_WAITING_STATUS_CODE = 1000

# ROMA作业等待状态
# ROMA job waiting status
ROMA_JOB_WAITING_STATUS = 'JOB_WAITING'

# 检查ROMA等待作业状态的间隔
# Interval for checking ROMA waiting job status
CHECK_ROMA_WAITING_JOB_STATUS_INTERVAL = 5

# ROMA训练作业默认优先级
# ROMA train job default priority
ROMA_TRAIN_JOB_DEFAULT_PRIORITY = 1

# 本地训练类型
# Local train type
LOCAL_TRAIN_TYPE = 'local'

# 本地训练目录
# Local train directory
LOCAL_TRAIN_DIR = "~/modelarts-python-sdk/local_train"

# 应用创建Y参数
# App create Y params
APP_CREATE_Y_PARAMS = {'application_name', 'application_version', 'source_type', 'source_location',
                       'initial_config'}

# 应用创建N参数
# App create N params
APP_CREATE_N_PARAMS = {'description', 'workspace_id', 'cmd', 'deployment_constraints', 'specification',
                       'market_flag'}

# 模型创建参数
# Model create params
MODEL_CREATE_PARAMS = {'model_name', 'model_version', 'source_location',
                       'source_job_id', 'source_job_version',
                       'source_type', 'model_type', 'model_algorithm',
                       'description', 'execution_code', 'input_params',
                       'output_params', 'dependencies', 'model_metrics',
                       'apis', 'runtime', 'install_type', 'model_docs', 'initial_config'}

# 模型索引参数
# Model index params
MODEL_INDEX_PARAMS = {'model_name', 'model_version', 'model_status',
                      'description', 'offset', 'limit', 'sort_by',
                      'order'}

# 服务部署参数
# Service deploy params
SERVICE_DEPLOY_PARAMS = {'service_name', 'description', 'infer_type', 'vpc_id',
                         'subnet_network_id',
                         'security_group_id', 'configs', 'cluster_id',
                         'schedule'}

# 服务索引参数
# Service index params
SERVICE_INDEX_PARAMS = {'service_id', 'service_name', 'infer_type', 'offset',
                        'limit', 'sort_by', 'order', 'model_id',
                        'service_status'}

# 本地推理日志
# Local infer log
LOCAL_INFER_LOG = "~/log/local_infer_log/"

# OBS头格式
# OBS head format
OBS_HEAD_FORMAT = 'obs://'

# S3头格式
# S3 head format
S3_HEAD_FORMAT = 's3://'

# ANACONDA目录
# ANACONDA directory
ANACONDA_DIR = "ANACONDA_DIR"

# 默认ANACONDA目录
# Default ANACONDA directory
DEFAULT_ANACONDA_DIR = "/home/ma-user/anaconda" + \
                       sys.version.split()[0].split(".")[0]

# 默认环境路径
# Default environment path
DEFAULT_ENVIRONMENT_PATH = os.path.join(os.environ.get(
    ANACONDA_DIR, DEFAULT_ANACONDA_DIR), "envs/")

# 环境路径环境变量名称
# Environment path env name
ENVIRONMENT_PATH_ENV_NAME = "ENVIRONMENT-PREFIX-PATH"

# 锁目录
# Lock directory
LOCK_DIR = "locks"

# 环境安装锁
# Environment install lock
ENVIRONMENT_INSTALL_LOCK = "install_modelarts_conda"

# Docker镜像构建目录
# Docker image build directory
DOCKER_IMAGE_BUILD_DIR = "/home/ma-user/work/"

# 默认pip配置文件路径
# Default pip config file path
DEFAULT_PIP_CONFIG_PATH = "/home/ma-user/.pip/pip.conf"

# 用户pip配置文件路径
# User pip config file path
USER_PIP_CONFIG_PATH = "USER_PIP_CONFIG_PATH"

# Docker镜像构建成功
# Docker image build success
DOCKER_IMAGE_BUILD_SUCC = "success"

# Docker镜像构建最大时间
# Docker image build max time
DOCKER_IMAGE_BUILD_MAX_TIME = 300

# 推理pip安装程序
# Infer pip installer
INFER_PIP_INSTALLER = "pip"

# 推理包约束字典
# Infer package restraint dict
INFER_PACKAGE_RESTRAINT_DICT = {'EXACT': '==', 'ATLEAST': '>=', 'ATMOST': '<='}

# 推理安装类型
# Infer install type
INFER_INSTALL_TYPE = ["real-time", "edge", "batch"]
# 对于这些AI框架及其推理版本，
# 请查看 https://support.huaweicloud.com/engineers-modelarts/modelarts_23_0207.html
# For these AI frameworks and their versions of infer,
# check https://support.huaweicloud.com/engineers-modelarts/modelarts_23_0207.html
INFER_SUPPORT_RUNTIME_DICT = {
    'TensorFlow': {
        'python2.7': {'1.8': 'python2.7', '1.13': 'tf1.13-python2.7-cpu', '1.13-gpu': 'tf1.13-python2.7-gpu'},
        'python3.6': {'1.8': 'python3.6', '1.13': 'tf1.13-python3.6-cpu', '1.13-gpu': 'tf1.13-python3.6-gpu'},
        'python3.7': {'2.1': 'tf2.1-python3.7', '1.13': 'tf1.13-python3.7-cpu', '1.13-gpu': 'tf1.13-python3.7-gpu'}
    },
    'MXNet': {
        'python2.7': {'1.2': 'python2.7'},
        'python3.6': {'1.2': 'python3.6'},
        'python3.7': {'1.2': 'python3.7'}
    },
    'Caffe': {
        'python2.7': {'1.0': 'python2.7', '1.0-cpu': 'python2.7-cpu', '1.0-gpu': 'python2.7-gpu'},
        'python3.6': {'1.0': 'python3.6', '1.0-cpu': 'python3.6-cpu', '1.0-gpu': 'python3.6-gpu'},
        'python3.7': {'1.0': 'python3.7', '1.0-cpu': 'python3.7-cpu', '1.0-gpu': 'python3.7-gpu'}
    },
    'Spark_MLlib': {
        'python2.7': {'2.3': 'python2.7'},
        'python3.6': {'2.3': 'python3.6'}
    },
    'Scikit_Learn': {
        'python2.7': {'0.20': 'python2.7'},
        'python3.6': {'0.20': 'python3.6'}
    },
    'XGBoost': {
        'python2.7': {'0.80': 'python2.7'},
        'python3.6': {'0.80': 'python3.6'}
    },
    'PyTorch': {
        'python2.7': {'1.0': 'python2.7'},
        'python3.6': {'1.0': 'python3.6',
                      '1.4': 'python3.6',
                      '1.5': 'python3.6',
                      '1.6': 'python3.6',
                      '1.7': 'python3.6',
                      '1.8': 'python3.6',
                      '1.9': 'python3.6',
                      },
        'python3.7': {'1.0': 'python3.7',
                      '1.4': 'pytorch1.4-python3.7',
                      '1.5': 'python3.7',
                      '1.6': 'python3.7',
                      '1.7': 'python3.7',
                      '1.8': 'python3.7',
                      '1.9': 'python3.7'
                      }
    }
}
# 推理运行时到环境的映射
# Infer runtime to environment mapping
INFER_RUNTIME_TO_ENVIRONMENT = {
    'TensorFlow': {
        'python2.7': {'pip_packages': ['tensorflow==1.8.0', 'tensorflow-serving-api==1.13.0'],
                      'conda_packages': ['python=2.7']},
        'python3.6': {'pip_packages': ['tensorflow==1.8.0', 'tensorflow-serving-api==1.13.0'],
                      'conda_packages': ['python=3.6.2']},
        'tf1.13-python2.7-gpu': {'pip_packages': ['tensorflow-gpu==1.13.2'], 'conda_packages': ['python=2.7']},
        'tf1.13-python2.7-cpu': {'pip_packages': ['tensorflow==1.13.2'], 'conda_packages': ['python=2.7']},
        'tf1.13-python3.6-gpu': {'pip_packages': ['tensorflow-gpu==1.13.2'], 'conda_packages': ['python=3.6.2']},
        'tf1.13-python3.6-cpu': {'pip_packages': ['tensorflow==1.13.2'], 'conda_packages': ['python=3.6.2']},
        'tf1.13-python3.7-gpu': {'pip_packages': ['tensorflow-gpu==1.13.2'], 'conda_packages': ['python=3.7']},
        'tf1.13-python3.7-cpu': {'pip_packages': ['tensorflow==1.13.2'], 'conda_packages': ['python=3.7']},
        'tf2.1-python3.7': {'pip_packages': ['tensorflow==2.1'], 'conda_packages': ['python=3.7']}
    },
    'MXNet': {
        'python2.7': {'pip_packages': ['mxnet==1.2.1', 'mxnet-model-server==0.3'],
                      'conda_packages': ['python=2.7']},
        'python3.6': {'pip_packages': ['mxnet==1.2.1', 'mxnet-model-server==0.3'],
                      'conda_packages': ['python=3.6.2']},
        'python3.7': {'pip_packages': ['mxnet==1.2.1', 'mxnet-model-server==0.3'],
                      'conda_packages': ['python=3.7']}
    },
    'Caffe': {  # caffe does not support local infer, we only record runtimes
    'Caffe': {  # caffe不支持本地推理，我们只记录运行时
        'python2.7': {}, 'python3.6': {}, 'python3.7': {},
        'python2.7-gpu': {}, 'python3.6-gpu': {}, 'python3.7-gpu': {},
        'python2.7-cpu': {}, 'python3.6-cpu': {}, 'python3.7-cpu': {}
    },
    'Spark_MLlib': {
        'python2.7': {'pip_packages': ['pyspark==2.3.2'], 'conda_packages': ['python=2.7']},
        'python3.6': {'pip_packages': ['pyspark==2.3.2'], 'conda_packages': ['python=3.6.2']}
    },
    'Scikit_Learn': {
        'python2.7': {'pip_packages': ['scikit-learn==0.20.0'], 'conda_packages': ['python=2.7']},
        'python3.6': {'pip_packages': ['scikit-learn==0.20.0'], 'conda_packages': ['python=3.6.2']}
    },
    'XGBoost': {
        'python2.7': {'pip_packages': ['xgboost==0.80'], 'conda_packages': ['python=2.7']},
        'python3.6': {'pip_packages': ['xgboost==0.80'], 'conda_packages': ['python=3.6.2']}
    },
    'PyTorch': {
        'python2.7': {'pip_packages': ['torch==1.0.0', 'torchvision==0.2.1'], 'conda_packages': ['python=2.7']},
        'python3.6': {'pip_packages': ['torch==1.0.0', 'torchvision==0.2.1'], 'conda_packages': ['python=3.6.2']},
        'python3.7': {'pip_packages': ['torch==1.0.0', 'torchvision==0.2.1'], 'conda_packages': ['python=3.7']},
        'pytorch1.4-python3.7': {'pip_packages': ['torch==1.4.0', 'torchvision==0.5.0'],
                                 'conda_packages': ['python=3.7']}
    }
}

# 推理框架别名
# Infer framework alias
INFER_FRAMEWORK_ALIAS = {
    "tensorflow": ["tensorflow", "tensorflow-gpu"],
    "spark_mllib": ["pyspark"],
    "pytorch": ["torch"],
    "scikit_learn": ["scikit-learn"],
    "mxnet": ["mxnet-cu90", "mxnet"]
}

# 模型本地位置
# Model local location
MODEL_LOCAL_LOCATION = "LOCAL_SOURCE"

# 模型OBS位置
# Model OBS location
MODEL_OBS_LOCATION = "OBS_SOURCE"

# 模型镜像位置
# Model image location
MODEL_IMAGE_LOCATION = "IMAGE_SOURCE"

# 模型源位置类型
# Model source locations type
MODEL_SOURCE_LOCATIONS_TYPE = {MODEL_LOCAL_LOCATION, MODEL_OBS_LOCATION, MODEL_IMAGE_LOCATION}

# 模型源位置
# Model source location
MODEL_SOURCE_LOCATION = "source_location"

# 模型算法模式
# Model algorithm pattern
MODEL_ALGORITHM_PATTERN = u"^[a-z|A-Z][^&!'\\\"<>=\u4e00-\u9fa5]{0,35}$"

# 包模式
# Package pattern
PACKAGE_PATTERN = u"^[^(|);&$?"<>`!'=\u4e00-\u9fa5\\s]{1,256}$"

# 模型名称模式
# Model name pattern
MODEL_NAME_PATTERN = u"^[a-zA-Z0-9\u4e00-\u9fa5-_]{1,64}$"

# 模型版本模式
# Model version pattern
MODEL_VERSION_PATTERN = "^(\d\.|[1-9]\d\.){2}(\d|([1-9]\d))$"

# 模型描述模式
# Model description pattern
MODEL_DESCRIPTION_PATTERN = "^[^&!'\\\"<>=]{1,100}$"

# 文档名称模式
# Doc name pattern
DOC_NAME_PATTERN = "^[^&!'\\\"<>=]{1,48}$"

# 文档URL模式
# Doc URL pattern
DOC_URL_PATTERN = "http[s]?://[^/]+.+"

# 源位置模式
# Source location pattern
SOURCE_LOCATION_PATTERN = "http[s]?://[^/]+/.+"

# 错误最大行数
# Error max line num
ERR_MAX_LINE_NUM = 100

# 域模式
# Domain pattern
DOMAIN_PATTERN = u"(?=^.{3,255}$)^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+.?$"

# HTTP状态码200
# HTTP status code 200
HTTP_STATUS_CODE_200 = 200

# HTTP状态码299
# HTTP status code 299
HTTP_STATUS_CODE_299 = 299

# 本地推理日志文件名
# Local infer log file name
LOCAL_INFER_LOG_FILE_NAME = "log.txt"

# 挂载目录
# Mount directory
MOUNT_DIR = "/home/ma-user/work"

# 上传模式
# Upload mode
UPLOAD_MODE = 'upload'

# 目录模式
# Dir mode
DIR_MODE = 'dir'

# 分隔符
# Separator
SEP = '/'

# 凭证配置文件
# Credential profiles file
CREDENTIAL_PROFILES_FILE = 'CREDENTIAL_PROFILES_FILE'

# AWS凭证配置文件
# AWS credential profiles file
AWS_CREDENTIAL_PROFILES_FILE = 'AWS_CREDENTIAL_PROFILES_FILE'

# NB用户
# NB user
NB_USER = "NB_USER"

# for ascend training
# 用于ascend训练
NBSTART_HCCL_FILE_PATH = "/user/config/nbstart_hccl.json"

# 作业启动HCCL文件路径
# Jobstart HCCL file path
JOBSTART_HCCL_FILE_PATH = "/user/config/jobstart_hccl.json"

# 查询训练状态周期
# Query train status period
QUERY_TRAIN_STATUS_PERIOD = 30

# 训练输出数据同步周期
# Train output data sync period
TRAIN_OUTPUT_DATA_SYNC_PERIOD = 30

# 文件权限
# File permission
FILE_PERMISSION = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP  # 640